package cn.com.dashihui.web.controller;

import java.util.ArrayList;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import com.jfinal.aop.Duang;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import cn.com.dashihui.kit.DatetimeKit;
import cn.com.dashihui.kit.ExcelExportUtil.Pair;
import cn.com.dashihui.web.base.BaseController;
import cn.com.dashihui.web.dao.AuthDownload;
import cn.com.dashihui.web.dao.ExchangeOrder;
import cn.com.dashihui.web.dao.ExchangeOrderLog;
import cn.com.dashihui.web.dao.Logistics;
import cn.com.dashihui.web.dao.OrderLogistics;
import cn.com.dashihui.web.dao.SendSeller;
import cn.com.dashihui.web.dao.Store;
import cn.com.dashihui.web.dao.User;
import cn.com.dashihui.web.service.AuthDownloadService;
import cn.com.dashihui.web.service.ExchangeOrderService;
import cn.com.dashihui.web.service.StoreService;
import cn.com.dashihui.web.service.UserService;

@RequiresAuthentication
public class ExchangeOrderController extends BaseController {
	//使用Duang.duang进行封装，使普通类具有事务的功能
	private ExchangeOrderService service = Duang.duang(ExchangeOrderService.class);
	private StoreService storeService = new StoreService();
	private UserService userService = new UserService();
	private AuthDownloadService downloadService=new AuthDownloadService();
	/**
	 * 订单列表页面
	 */
	public void index(){
		List<Record> list=storeService.findAllSeller();
    	setAttr("list", list);
		render("index.jsp");
	}
	/**
	 * 获得订单列表数据
	 */
	public void page(){
		int pageNum = getParaToInt(0, 1);
		int pageSize = getParaToInt("pageSize", PropKit.getInt("constants.pageSize"));
		//订单编号
		String exchangeOrderNum = getPara("exchangeOrderNum");
		//下单时间范围
		String beginDate = getPara("beginDate");
		String endDate = getPara("endDate");
		//订单状态
		int state = getParaToInt("state",0);
		//买家电话
		String tel = getPara("tel");
		//买家姓名
		String name = getPara("name");
		//公司ID
		String sellerId=getPara("sellerId");
		//分公司ID
		String storeId=getPara("storeId");
		Page<Record> findByPage = service.findByPage(pageNum,pageSize,exchangeOrderNum,beginDate,endDate,state,sellerId,tel,name,storeId);
		renderResult(0,findByPage);
	}
	/**
	 * 会员详情
	 */
	public void userdetail(){
		int id = getParaToInt(0,0);
		System.out.println(id);
		if(id!=0){
		User user=service.findById(id);
			setAttr("user", user);
			List<Store> storeList=service.findStoreList();
			setAttr("storeList", storeList);
			List<Record> userList=service.findUserList(user.get("store"));
			setAttr("userList", userList);
		}
		render("userdetail.jsp");
	}
	/**
	 * 查询订单详情
	 */
	public void detail(){
		String exchangeOrderNum = getPara("orderNum");
		ExchangeOrder exchangeOrder = service.findExchangeOrderByExchangeOrderNum(exchangeOrderNum);
		if(StrKit.notNull(exchangeOrder)){
			setAttr("obj", exchangeOrder);
			setAttr("goodsList", service.findGoodsListByExchangeOrderNum(exchangeOrderNum));
			setAttr("logList", service.findLogListByExchangeOrderNum(exchangeOrderNum));
			setAttr("eval", service.findEvalByExchangeOrderNum(exchangeOrderNum));
		} 
		render("detail.jsp");
	}
    /**
     * 订单统计查询所需积分总和现金价格总和
     */
	public void findTotal(){
		//订单编号
		String exchangeOrderNum = getPara("exchangeOrderNum");
		//下单时间范围
		String beginDate = getPara("beginDate");
		String endDate = getPara("endDate");
		//订单状态
		int state = getParaToInt("state",0);
		//买家电话
		String tel = getPara("tel");
		//买家姓名
		String name = getPara("name");
		//公司ID
		String sellerId=getPara("sellerId");
		//分公司ID
		String storeId=getPara("storeId");
		renderSuccess(service.findTotal(beginDate, endDate,sellerId,storeId,tel,name,exchangeOrderNum,state));
	}
	/**
	 * 获得订单列表数据
	 */
	public void goodsExchangeOrder(){
		int pageNum = getParaToInt(0, 1);
		int pageSize = getParaToInt("pageSize", PropKit.getInt("constants.pageSize"));
		//订单编号
		String exchangeOrderNum = getPara("exchangeOrderNum");
		//下单时间范围
		String beginDate = getPara("beginDate");
		String endDate = getPara("endDate");
		//订单状态
		int state = getParaToInt("state",0);
		//买家电话
		String tel = getPara("tel");
		//公司ID
		String sellerId=getPara("sellerId");
		//分公司ID
		String storeId=getPara("storeId");
		//商品Id
		int id=getParaToInt("id",0);
		renderResult(0,service.goodsExchangeOrder(pageNum,pageSize,exchangeOrderNum,beginDate,endDate,state,sellerId,tel,storeId,id));
	}
	/**
	 * 去添加物流信息
	 */
	public void toAddWaybill(){
		String orderNum = getPara("orderNum");
		List<Logistics> listLogistics = service.findAllLogistics();
		List<SendSeller> listSendSeller = service.findSendSeller();
		setAttr("listSendSeller", listSendSeller);
		setAttr("listLogistics", listLogistics);
		setAttr("orderNum", orderNum);
		render("addwaybill.jsp");
	}
	/**
	 * 去物流信息详情
	 */
	public void WBDetail(){
		String orderNum = getPara("orderNum");
		List<Logistics> listLogistics = service.findAllLogistics();
		List<SendSeller> listSendSeller = service.findSendSeller();
		setAttr("listSendSeller", listSendSeller);
		setAttr("listLogistics", listLogistics);
		setAttr("orderNum", orderNum);
		OrderLogistics orderLogistics = service.findWBByOrderNum(orderNum);
		setAttr("orderLogistics", orderLogistics);
		render("wbdetail.jsp");
	}
	/**
	 * 存储物流和订单信息，预设物流单号——订单为many to one
	 */
	public void doAddWaybillForm(){
		//订单号
		String orderNum = getPara("orderNum");
		//物流单号
		String logisticCode = getPara("logisticCode");
		//运费
		String orderPay = getPara("orderPay");
		if (service.findExistsByLogisticCode(logisticCode)) {
			renderResult(1);
			return;
		}
		if (service.findExistsByOrderNum(orderNum)) {
			renderResult(2);
			return;
		}
		//物流公司代码
		String charset = getPara("charset");
		//发货公司
		String sendSeller = getPara("sendSeller");
		OrderLogistics orderLogistics = new OrderLogistics();
		orderLogistics.set("orderCode", orderNum)
						.set("logisticCode", logisticCode)
						.set("sendSeller", sendSeller)
						.set("orderPay", orderPay)
						.set("createDate", DatetimeKit.getFormatDate("yyyy-MM-dd-HH-mm-ss"))
						.set("charset", charset);
		if (orderLogistics.save()) {
			ExchangeOrder order = service.findByOrderNum(orderNum);
			int orderState = 6;
			order.set("orderState", orderState);
			if (order.update()) {
				ExchangeOrderLog exchangeOrderLog = new ExchangeOrderLog();
				int type = 5;
				int userid = order.get("userid");
				User user = userService.findUserById(userid);
				String name = user.get("name");
				String action = "已出库";
				String content = "已支付订单已出库";
				exchangeOrderLog.set("orderNum", orderNum)
								.set("type", type)
								.set("user", name)
								.set("action", action)
								.set("content", content)
								.set("createDate", DatetimeKit.getFormatDate("yyyy-MM-dd HH:mm:ss"))
								.save();
				renderSuccess();
			}
		}
	}
	/**
	 * excel导出
	 */
	public void doExcel(){
		List<Pair> titles = new ArrayList<Pair>();
		titles.add(new Pair("exchangeOrderNum", "订单号"));
		titles.add(new Pair("card", "会员卡号"));
		titles.add(new Pair("name", "会员姓名"));
		titles.add(new Pair("tel", "联系方式"));
	    titles.add(new Pair("xdstore", "下单分公司"));
	    titles.add(new Pair("goodsid", "兑换物品ID"));
	    titles.add(new Pair("goodsName", "兑换物品名称"));
	    titles.add(new Pair("specTitle", "兑换物品规格"));
	    titles.add(new Pair("startDate", "下单时间"));
	    titles.add(new Pair("countnum", "兑换数量"));
	    titles.add(new Pair("pointType", "积分类型"));
	    titles.add(new Pair("payPoint", "所需积分"));
	    titles.add(new Pair("amount", "现金价格"));
	    titles.add(new Pair("payDate", "支付时间"));
	    titles.add(new Pair("bespokeDate", "预约时间"));
	    titles.add(new Pair("guoDate", "兑换有效期"));
	    titles.add(new Pair("dhstore", "兑换分公司"));
	    titles.add(new Pair("deliverDate", "兑换时间"));
	    titles.add(new Pair("toBossOneId", "营业部"));
	    titles.add(new Pair("payState", "状态"));
	     //订单编号
	  		String exchangeOrderNum = getPara("exchangeOrderNum");
	  		//下单时间范围
	  		String beginDate = getPara("beginDate");
	  		String endDate = getPara("endDate");
	  		//订单状态
	  		int state = getParaToInt("state",0);
	  		//买家电话
	  		String tel = getPara("tel");
	  		//买家姓名
	  		String name = getPara("name");
	  		//公司ID
	  		String sellerId=getPara("sellerId");
	  		//分公司ID
	  		String storeId=getPara("storeId");
		List<Record> list=service.findExcelByPage(exchangeOrderNum,beginDate,endDate,state,sellerId,tel,name,storeId);
		List<Record> listz=new ArrayList<Record>();
		for (int i = 0; i < list.size(); i++) {
			Record record=new Record();
			record.set("tel", list.get(i).getStr("tel"));
				record.set("exchangeOrderNum",list.get(i).get("exchangeOrderNum"));
				record.set("card",list.get(i).get("card"));
				record.set("name",list.get(i).get("name"));
				record.set("xdstore", list.get(i).get("xdstore"));
				record.set("goodsid", list.get(i).get("goodsid"));
				record.set("goodsName", list.get(i).get("goodsName"));
				record.set("specTitle", list.get(i).get("specTitle"));
				record.set("startDate", list.get(i).get("startDate"));
				record.set("countnum", list.get(i).get("countnum"));
				if(list.get(i).get("pointType").equals(1)){
					record.set("pointType", "积分");
				}else if(list.get(i).get("pointType").equals(2)){
					record.set("pointType", "抵扣券");
				}else if(list.get(i).get("pointType").equals(3)){
					record.set("pointType", "惠券");
				}
				record.set("payPoint", list.get(i).get("payPoint"));
				record.set("amount", list.get(i).get("amount"));
				record.set("payDate", list.get(i).get("payDate"));
				record.set("bespokeDate", list.get(i).get("bespokeDate"));
				record.set("guoDate", list.get(i).get("guoDate"));
				record.set("dhstore", list.get(i).get("dhstore"));
				record.set("deliverDate", list.get(i).get("deliverDate"));
				record.set("toBossOneId", list.get(i).get("toBossOneId"));
				if(list.get(i).get("payState").equals(1)){
					if(list.get(i).get("delState").equals(0)){
						record.set("payState", "待付款");
					}else if(list.get(i).get("delState").equals(1)){
						record.set("payState", "已取消");
					}
				}else if(list.get(i).get("payState").equals(2)){
				   if(list.get(i).get("exchangeOrderState").equals(1)){
						if(list.get(i).get("tuistate").equals(0)){
							record.set("payState", "未兑换");
						}else if(list.get(i).get("tuistate").equals(1)){
							record.set("payState", "退款中");
						}else if(list.get(i).get("tuistate").equals(2)){
							record.set("payState", "已退款");
						}
						
					}else if(list.get(i).get("exchangeOrderState").equals(2)){
						record.set("payState", "已付款");
					}else if(list.get(i).get("exchangeOrderState").equals(3)){
						
						if(list.get(i).get("tuistate").equals(0)){
							record.set("payState", "已过期");
						}else if(list.get(i).get("tuistate").equals(1)){
							record.set("payState", "退款中");
						}else if(list.get(i).get("tuistate").equals(2)){
							record.set("payState", "已退款");
						}
					}else if(list.get(i).get("exchangeOrderState").equals(4)){
						record.set("payState", "已删除");
					}
				}
			listz.add(record);
 		}
		//向登录下载统计表中添加数据   订单统计
		Record downObj=downloadService.findByUserId(getCurrentUser().getInt("id"));
		AuthDownload download=new AuthDownload();
		download.set("logName","平台端")
			        .set("name", downObj.get("trueName"))
			        .set("accountRole", downObj.get("alias"))
			        .set("storeName", "公司总部")
			        .set("exchangeOrderDownload", 1)
                   .set("downloadDate",DatetimeKit.getFormatDate("yyyy-MM-dd HH:mm:ss"));

		download.save();
 
		// 导出
		service.export(getResponse(), getRequest(),titles, listz);		
		renderNull();
	}
	/**
	 * excel导出
	 */
	public void doGoodsExcel(){
		List<Pair> titles = new ArrayList<Pair>();
		titles.add(new Pair("exchangeOrderNum", "订单号"));
		titles.add(new Pair("card", "会员卡号"));
		titles.add(new Pair("name", "会员姓名"));
		titles.add(new Pair("tel", "联系方式"));
	    titles.add(new Pair("xdstore", "下单分公司"));
	    titles.add(new Pair("goodsid", "兑换物品ID"));
	    titles.add(new Pair("goodsName", "兑换物品名称"));
	    titles.add(new Pair("startDate", "下单时间"));
	    titles.add(new Pair("countnum", "兑换数量"));
	    titles.add(new Pair("pointType", "积分类型"));
	    titles.add(new Pair("payPoint", "所需积分"));
	    titles.add(new Pair("amount", "现金价格"));
	    titles.add(new Pair("payDate", "支付时间"));
	    titles.add(new Pair("guoDate", "兑换有效期"));
	    titles.add(new Pair("dhstore", "兑换分公司"));
	    titles.add(new Pair("deliverDate", "兑换时间"));
	    titles.add(new Pair("toBossOneId", "营业部"));
	    titles.add(new Pair("payState", "状态"));
	     //订单编号
	  		String exchangeOrderNum = getPara("exchangeOrderNum");
	  		//下单时间范围
	  		String beginDate = getPara("beginDate");
	  		String endDate = getPara("endDate");
	  		//订单状态
	  		int state = getParaToInt("state",0);
	  		//买家电话
	  		String tel = getPara("tel");
	  		//公司ID
	  		String sellerId=getPara("sellerId");
	  		//分公司ID
	  		String storeId=getPara("storeId");
	  		//商品Id
			int id=getParaToInt("id",0);
		List<Record> list=service.findGoodsExcelByPage(exchangeOrderNum,beginDate,endDate,state,sellerId,tel,storeId,id);
		List<Record> listz=new ArrayList<Record>();
		for (int i = 0; i < list.size(); i++) {
			Record record=new Record();
			record.set("tel", list.get(i).getStr("tel"));
				record.set("exchangeOrderNum",list.get(i).get("exchangeOrderNum"));
				record.set("card",list.get(i).get("card"));
				record.set("name",list.get(i).get("name"));
				record.set("xdstore", list.get(i).get("xdstore"));
				record.set("goodsid", list.get(i).get("goodsid"));
				record.set("goodsName", list.get(i).get("goodsName"));
				record.set("startDate", list.get(i).get("startDate"));
				record.set("countnum", list.get(i).get("countnum"));
				if(list.get(i).get("pointType").equals(1)){
					record.set("pointType", "积分");
				}else if(list.get(i).get("pointType").equals(2)){
					record.set("pointType", "抵扣券");
				}else if(list.get(i).get("pointType").equals(3)){
					record.set("pointType", "惠券");
				}
				record.set("payPoint", list.get(i).get("payPoint"));
				record.set("amount", list.get(i).get("amount"));
				//record.set("payDate", list.get(i).get("payDate").toString().substring(0,19));
				record.set("payDate", list.get(i).get("payDate"));
				record.set("guoDate", list.get(i).get("guoDate"));
				record.set("dhstore", list.get(i).get("dhstore"));
				record.set("deliverDate", list.get(i).get("deliverDate"));
				record.set("toBossOneId", list.get(i).get("toBossOneId"));
				if(list.get(i).get("payState").equals(1)){
					if(list.get(i).get("delState").equals(0)){
						record.set("payState", "待付款");
					}else if(list.get(i).get("delState").equals(1)){
						record.set("payState", "已取消");
					}
				}else if(list.get(i).get("payState").equals(2)){
					if(list.get(i).get("exchangeOrderState").equals(1)){
						if(list.get(i).get("tuistate").equals(0)){
							record.set("payState", "未兑换");
						}else if(list.get(i).get("tuistate").equals(1)){
							record.set("payState", "退款中");
						}else if(list.get(i).get("tuistate").equals(2)){
							record.set("payState", "已退款");
						}
						
					}else if(list.get(i).get("exchangeOrderState").equals(2)){
						record.set("payState", "已付款");
					}else if(list.get(i).get("exchangeOrderState").equals(3)){
						
						if(list.get(i).get("tuistate").equals(0)){
							record.set("payState", "已过期");
						}else if(list.get(i).get("tuistate").equals(1)){
							record.set("payState", "退款中");
						}else if(list.get(i).get("tuistate").equals(2)){
							record.set("payState", "已退款");
						}
					}else if(list.get(i).get("exchangeOrderState").equals(4)){
						record.set("payState", "已删除");
					}
				}
			listz.add(record);
 		}
		// 导出
		service.export(getResponse(), getRequest(),titles, listz);		
		renderNull();
	}
	/**
	 * 积分兑换列表
	 */
	public void dixian(){
		List<Record> list=storeService.findAllSeller();
    	setAttr("list", list);
    	List<Record> listStore=storeService.findAllStore();
    	setAttr("listStore", listStore);
		render("dixianlist.jsp");
	}
	/**
	 * 获得抵现列表数据
	 */
	public void dixianpage(){
		int pageNum = getParaToInt(0, 1);
		int pageSize = getParaToInt("pageSize", PropKit.getInt("constants.pageSize"));
		//订单编号
		String toBossOneId = getPara("toBossOneId");
		//下单时间范围
		String beginDate = getPara("beginDate");
		String endDate = getPara("endDate");
		//买家电话
		String phone = getPara("phone");
		//公司ID
		String sellerId=getPara("sellerId");
		//分公司ID
		String storeId=getPara("storeId");
		renderResult(0,service.findBydixianPage(pageNum,pageSize,toBossOneId,beginDate,endDate,sellerId,phone,storeId));
	}
	/**
	 * excel导出
	 */
	public void doDixianExcel(){
	  List<Pair> titles = new ArrayList<Pair>();
		titles.add(new Pair("title", "消费分公司"));
		titles.add(new Pair("sellerName", "所属公司"));
		titles.add(new Pair("name", "会员姓名"));
		titles.add(new Pair("phone", "联系方式"));
	    titles.add(new Pair("store", "开卡分公司"));
	    titles.add(new Pair("toBossOneId", "销售"));
	    titles.add(new Pair("mun", "消费项目"));
	    titles.add(new Pair("money", "消费金额"));
	    titles.add(new Pair("amount", "抵现金额"));
	    titles.add(new Pair("date", "消费时间"));
        //订单编号
		String toBossOneId = getPara("toBossOneId");
		//下单时间范围
		String beginDate = getPara("beginDate");
		String endDate = getPara("endDate");
		//买家电话
		String phone = getPara("phone");
		//公司ID
  		String sellerId=getPara("sellerId");
  		//分公司ID
  		String storeId=getPara("storeId");
		List<Record> list=service.findExcelByPage(toBossOneId,beginDate,endDate,sellerId,phone,storeId);
		List<Record> listz=new ArrayList<Record>();
		for (int i = 0; i < list.size(); i++) {
			Record record=new Record();
			record.set("title", list.get(i).getStr("title"));
			record.set("sellerName", list.get(i).getStr("sellerName"));
			record.set("name",list.get(i).get("name"));
			record.set("phone",list.get(i).get("phone"));
			record.set("store", list.get(i).get("store"));
			record.set("toBossOneId", list.get(i).get("toBossOneId"));
			record.set("mun", list.get(i).get("mun"));
			record.set("money", list.get(i).get("money"));
			record.set("amount", list.get(i).get("amount"));
			record.set("date", list.get(i).get("date"));
			listz.add(record);
 		}
		//向登录下载统计表中添加数据 抵现明细统计下载
		Record downObj=downloadService.findByUserId(getCurrentUser().getInt("id"));
		AuthDownload download=new AuthDownload();
		download.set("logName","平台端")
			        .set("name", downObj.get("trueName"))
			        .set("accountRole", downObj.get("alias"))
			        .set("storeName", "公司总部")
			        .set("arrivedDownload", 1)
                   .set("downloadDate",DatetimeKit.getFormatDate("yyyy-MM-dd HH:mm:ss"));

		download.save();
		// 导出
		service.exportdi(getResponse(), getRequest(),titles, listz);		
		renderNull();
	}
	
		public void convert(){
			int userId=getParaToInt("userId", 0);	
			setAttr("userId", userId);
			render("index.jsp");
		}

		/**
		 * 展示此会员的所有线上订单
		 */
		public void doConvert(){
			int userId=getParaToInt("userId", 0);	
			int pageNum = getParaToInt(0, 1);
			int pageSize = getParaToInt("pageSize", PropKit.getInt("constants.pageSize"));
			renderResult(0,service.findUserExchangeOrder(pageNum,pageSize,userId));	
		}
	    /***
	     *  导出此会员的所有线上订单
	     */
		public void doConvertExcel(){
			int userId=getParaToInt("userId", 0);	
			List<Pair> titles = new ArrayList<Pair>();
			titles.add(new Pair("exchangeOrderNum", "订单号"));
			titles.add(new Pair("card", "会员卡号"));
			titles.add(new Pair("name", "会员姓名"));
			titles.add(new Pair("tel", "联系方式"));
		    titles.add(new Pair("xdstore", "下单分公司"));
		    titles.add(new Pair("goodsid", "兑换物品ID"));
		    titles.add(new Pair("goodsName", "兑换物品名称"));
		    titles.add(new Pair("specTitle", "兑换物品规格"));
		    titles.add(new Pair("startDate", "下单时间"));
		    titles.add(new Pair("countnum", "兑换数量"));
		    titles.add(new Pair("pointType", "积分类型"));
		    titles.add(new Pair("payPoint", "所需积分"));
		    titles.add(new Pair("amount", "现金价格"));
		    titles.add(new Pair("payDate", "支付时间"));
		    titles.add(new Pair("bespokeDate", "预约时间"));
		    titles.add(new Pair("guoDate", "兑换有效期"));
		    titles.add(new Pair("dhstore", "兑换分公司"));
		    titles.add(new Pair("deliverDate", "兑换时间"));
		    titles.add(new Pair("toBossOneId", "营业部"));
		    titles.add(new Pair("payState", "状态"));
/*		     //订单编号
		  		String exchangeOrderNum = getPara("exchangeOrderNum");
		  		//下单时间范围
		  		String beginDate = getPara("beginDate");
		  		String endDate = getPara("endDate");
		  		//订单状态
		  		int state = getParaToInt("state",0);
		  		//买家电话
		  		String tel = getPara("tel");
		  		//公司ID
		  		String sellerId=getPara("sellerId");
		  		//分公司ID
		  		String storeId=getPara("storeId");*/
			List<Record> list=service.findUserExchangeOrder(userId);
			List<Record> listz=new ArrayList<Record>();
			for (int i = 0; i < list.size(); i++) {
				Record record=new Record();
				record.set("tel", list.get(i).getStr("tel"));
					record.set("exchangeOrderNum",list.get(i).get("exchangeOrderNum"));
					record.set("card",list.get(i).get("card"));
					record.set("name",list.get(i).get("name"));
					record.set("xdstore", list.get(i).get("xdstore"));
					record.set("goodsid", list.get(i).get("goodsid"));
					record.set("goodsName", list.get(i).get("goodsName"));
					record.set("specTitle", list.get(i).get("specTitle"));
					record.set("startDate", list.get(i).get("startDate"));
					record.set("countnum", list.get(i).get("countnum"));
					if(list.get(i).get("pointType").equals(1)){
						record.set("pointType", "积分");
					}else if(list.get(i).get("pointType").equals(2)){
						record.set("pointType", "抵扣券");
					}else if(list.get(i).get("pointType").equals(3)){
						record.set("pointType", "惠券");
					}
					record.set("payPoint", list.get(i).get("payPoint"));
					record.set("amount", list.get(i).get("amount"));
					record.set("payDate", list.get(i).get("payDate"));
					record.set("bespokeDate", list.get(i).get("bespokeDate"));
					record.set("guoDate", list.get(i).get("guoDate"));
					record.set("dhstore", list.get(i).get("dhstore"));
					record.set("deliverDate", list.get(i).get("deliverDate"));
					record.set("toBossOneId", list.get(i).get("toBossOneId"));
					if(list.get(i).get("payState").equals(1)){
						if(list.get(i).get("delState").equals(0)){
							record.set("payState", "待付款");
						}else if(list.get(i).get("delState").equals(1)){
							record.set("payState", "已取消");
						}
					}else if(list.get(i).get("payState").equals(2)){
					   if(list.get(i).get("exchangeOrderState").equals(1)){
							if(list.get(i).get("tuistate").equals(0)){
								record.set("payState", "未兑换");
							}else if(list.get(i).get("tuistate").equals(1)){
								record.set("payState", "退款中");
							}else if(list.get(i).get("tuistate").equals(2)){
								record.set("payState", "已退款");
							}
							
						}else if(list.get(i).get("exchangeOrderState").equals(2)){
							record.set("payState", "已付款");
						}else if(list.get(i).get("exchangeOrderState").equals(3)){
							
							if(list.get(i).get("tuistate").equals(0)){
								record.set("payState", "已过期");
							}else if(list.get(i).get("tuistate").equals(1)){
								record.set("payState", "退款中");
							}else if(list.get(i).get("tuistate").equals(2)){
								record.set("payState", "已退款");
							}
						}else if(list.get(i).get("exchangeOrderState").equals(4)){
							record.set("payState", "已删除");
						}
					}
				listz.add(record);
	 		}
			//向登录下载统计表中添加数据   订单统计
			Record downObj=downloadService.findByUserId(getCurrentUser().getInt("id"));
			AuthDownload download=new AuthDownload();
			download.set("logName","平台端")
				        .set("name", downObj.get("trueName"))
				        .set("accountRole", downObj.get("alias"))
				        .set("storeName", "公司总部")
				        .set("exchangeOrderDownload", 1)
	                   .set("downloadDate",DatetimeKit.getFormatDate("yyyy-MM-dd HH:mm:ss"));

			download.save();
			// 导出
			service.export(getResponse(), getRequest(),titles, listz);		
			renderNull();
		}
}
